//
//  MainMenu.m
//  Memory Mania
//
//  Created by Sanket Karkhanis on 2/20/12.
//  Copyright 2012 University of Southern California. All rights reserved.
//

#import "MainMenu.h"
#import "PlayerSelect.h"
#import "HelloWorldLayer.h"
#import "SimpleAudioEngine.h"

@implementation MainMenu

+(id) scene
{
    CCScene *scene = [CCScene node];
    MainMenu *layer = [MainMenu node];
    [scene addChild:layer];
    return  scene;
    
}

- (id)init
{
    self = [super init];
    if (self) {
        CCLabelTTF *instructions = [CCLabelTTF labelWithString:@"Instructions" fontName:@"Arial" fontSize:100];
        instructions.position = ccp(512,500);
        [self addChild: instructions z:1];
        CCMenuItem *highscore = [CCMenuItemFont itemFromString:@"HighScores" target:self selector:@selector(onHighscore:)];
        CCMenuItem *play = [CCMenuItemFont itemFromString:@"Play" target:self selector:@selector(onPlay:)];
        highscore.scale = 3.0f;
        play.scale = 3.0f;
        
        //background music
        //[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"Gentle.mp3"loop:YES];  
        //[[SimpleAudioEngine sharedEngine] preloadEffect:@"file2.aiff" ];
        
        //background
        CCSprite *MainBg = [CCSprite spriteWithFile:@"mighty-boy-brian-grass-bokeh-ipad-wallpaper.jpg"];		
        MainBg.anchorPoint = ccp(0.5,0.5);
        MainBg.position = ccp(512,384);
		//MainBg.opacity = 70;        
        [self addChild:MainBg z:0 tag:1];
        
        
        //play.position = ccp(700,200);
        CCMenu *menu = [CCMenu menuWithItems:highscore, play, nil];
        menu.position = ccp(512,200);
        [menu alignItemsHorizontallyWithPadding:100.0f];
        [self addChild:menu];
        
        // Initialization code here.
    }
    
    return self;
}

-(void) onHighscore: (id) sender
{
    //sound effect
    //[[SimpleAudioEngine sharedEngine]playEffect:@"explosion_large.caf"];
}

-(void) onPlay: (id) sender
{
    NSLog(@"To play screen2");
    [[CCDirector sharedDirector] replaceScene:[CCTransitionFlipAngular transitionWithDuration:1.0 scene:[PlayerSelect node]]]; 
}
@end
